import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/constants/font_family.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/fight_succ.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';

class CheckpointSuccTopWidget extends StatelessWidget {
  final FightSucc info;
  final String boss;
  const CheckpointSuccTopWidget({Key key, this.info, this.boss})
      : super(key: key);

  List<Widget> createStarsBg(int bgCount) {
    return List.generate(bgCount, (index) {
      return Image.asset(
        imageUtilYeXiu('checkpoint/icon_stars_bg@3x'),
        width: setRatio(30),
        height: setRatio(30),
      );
    }).toList();
  }

  List<Widget> createStars(int starsCount, String level) {
    return List.generate(starsCount, (index) {
      return Image.asset(
        imageUtilYeXiu('checkpoint/icon_stars_$level@3x'),
        width: setRatio(30),
        height: setRatio(30),
      );
    }).toList();
  }

  //关卡等级 等级分为 0 -- 未通关 10 -- C级 20 -- B级 30 -- A级 40 -- S级。
  String level(int grade) {
    switch (grade) {
      case 0:
        return 'c';
      case 10:
        return 'c';
      case 20:
        return 'b';
      case 30:
        return 'a';
      case 40:
        return 's';
      default:
        return 'c';
    }
  }

  int levelCount(int grade) {
    switch (grade) {
      case 0:
        return 0;
      case 10:
        return 2;
      case 20:
        return 3;
      case 30:
        return 4;
      case 40:
        return 5;
      default:
        return 0;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Image.asset(
          imageUtilYeXiu('checkpoint/icon_checkpoint_succ_reward_title@3x'),
          width: setRatio(140),
          height: setRatio(30),
        ),
        Positioned(
          left: setRatio(15),
          top: setRatio(3),
          child: Text(
            boss ?? '',
            style: TextStyle(
                fontStyle: FontStyle.italic,
                decoration: TextDecoration.none,
                color: Color(0xFFFFFFFF),
                fontFamily: FontFamily.PMZD,
                fontSize: setTextSp(20)),
          ),
        ),
        Container(
          width: setRatio(375),
          height: setRatio(270),
          transform: Matrix4.translationValues(0, setRatio(15), 0),
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage(imageUtilYeXiu(
                      'checkpoint/icon_checkpoint_succ_reward_top@3x')))),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Padding(
                padding: EdgeInsets.only(left: setRatio(22)),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Image.asset(
                      buildImageReward(level(info?.gradeScore?.grade ?? 0)),
                      width: setRatio(150),
                      height: setRatio(100),
                    ),
                    Stack(
                      children: <Widget>[
                        Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: createStarsBg(5),
                        ),
                        Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: createStars(
                                levelCount(info?.gradeScore?.grade ?? 0),
                                level(info?.gradeScore?.grade ?? 0))),
                      ],
                    ),
                    SizedBox(
                      height: setRatio(15),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Image.asset(
                          buildIconLevel(level(info?.gradeScore?.grade ?? 0)),
                          width: setRatio(30),
                          height: setRatio(30),
                        ),
                        Text.rich(
                          TextSpan(
                              children: [
                                TextSpan(text: '得分'),
                                TextSpan(
                                    text: '${info?.gradeScore?.score ?? 0}',
                                    style: buildTextStyle(
                                        info?.gradeScore?.grade ?? 0))
                              ],
                              style: TextStyle(
                                  fontStyle: FontStyle.italic,
                                  decoration: TextDecoration.none,
                                  color: Color(0xFFFFFFFF),
                                  fontFamily: FontFamily.PMZD,
                                  fontSize: setTextSp(22))),
                        )
                      ],
                    )
                  ],
                ),
              )
            ],
          ),
        ),
        Container(
          width: setRatio(360),
          height: setRatio(420),
          margin: EdgeInsets.only(left: setRatio(15)),
          child: Image.asset(
            imageUtilYeXiu('checkpoint/icon_checkpoint_succ_reward_role@3x'),
            width: setRatio(360),
            height: setRatio(420),
          ),
        )
      ],
    );
  }

  String buildIconLevel(String level) =>
      imageUtilYeXiu('checkpoint/icon_level_$level@3x');

  TextStyle buildTextStyle(int grade) {
    switch (grade) {
      case 0:
        return TextStyle(color: Color(0xFF52CF73));
      case 10:
        return TextStyle(color: Color(0xFF52CF73));
      case 20:
        return TextStyle(color: Color(0xFF6B9EFB));
      case 30:
        return TextStyle(color: Color(0xFF908EFF));
      case 40:
        return TextStyle(color: Color(0xFFFFBF13));
      default:
        return TextStyle(color: Color(0xFF52CF73));
    }
  }

  String buildImageReward(String level) =>
      imageUtilYeXiu('checkpoint/icon_checkpoint_succ_reward_$level@3x');
}
